<template>
  <div class="aside">
    <el-menu
      :default-active="$store.state.activeIndex"
      @select="handleSelect"
      router
    >
      <el-menu-item
        :route="{ name: 'index', path: '/index' }"
        index="14"
        v-if="!isLogin"
        >登录注册</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'tchIndex', path: '/tchIndex' }"
        index="1"
        v-if="info.role === 'tch'"
        >教师首页</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'stuIndex', path: '/stuIndex' }"
        index="11"
        v-if="info.role === 'stu'"
        >搜题</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'execEntry', path: '/execEntry' }"
        index="2"
        v-if="info.role === 'stu'"
        >练习</el-menu-item
      >
      <el-submenu index="page" v-if="info.role === 'tch'">
        <template slot="title">
          <span>卷库管理</span>
        </template>
        <el-menu-item
          :route="{ name: 'createPaper', path: '/createPaper' }"
          index="2-1"
          >创建试卷</el-menu-item
        >
        <el-menu-item
          :route="{ name: 'paperList', path: '/paperList' }"
          index="2-2"
          >试卷列表</el-menu-item
        >
      </el-submenu>

      <el-submenu index="subject" v-if="info.role === 'tch'">
        <template slot="title">
          <span>题库管理</span>
        </template>
        <el-menu-item
          :route="{ name: 'createSubject', path: '/createSubject' }"
          index="5-1"
          >创建试题</el-menu-item
        >
        <el-menu-item
          :route="{ name: 'subjectManage', path: '/subjectManage' }"
          index="5-2"
          >试题列表</el-menu-item
        >
      </el-submenu>

      <el-submenu index="class" v-if="info.role === 'tch'">
        <template slot="title">
          <span>班级管理</span>
        </template>
        <el-menu-item
          index="3-1"
          :route="{ name: 'classManage', path: '/classManage' }"
          >班级列表</el-menu-item
        >
        <el-menu-item
          index="3-2"
          :route="{ name: 'createClass', path: '/createClass' }"
          >创建班级</el-menu-item
        >
      </el-submenu>

      <el-menu-item
        :route="{ name: 'examList', path: '/examList' }"
        index="5"
        v-if="info.role === 'stu'"
        >计时考试</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'examRecord', path: '/examRecord' }"
        index="7"
        v-if="info.role === 'stu'"
        >考试记录</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'errorManage', path: '/errorManage' }"
        index="8"
        v-if="info.role === 'stu'"
        >错题管理</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'answerResult', path: '/answerResult' }"
        index="9"
        v-if="info.role === 'stu'"
        >数据统计</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'dataAnalysis', path: '/dataAnalysis' }"
        index="22"
        v-if="info.role === 'tch'"
        >数据统计</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'stuClass', path: '/stuClass' }"
        index="20"
        v-if="info.role === 'stu'"
        >我的班级</el-menu-item
      >
      <el-menu-item
        :route="{ name: 'person', path: '/person' }"
        index="10"
        v-if="info.role === 'stu' || info.role === 'tch'"
        >个人中心</el-menu-item
      >
    </el-menu>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["info", "isLogin"]),
  },
  methods: {
    handleSelect(key) {
      this.$store.commit("setActiveIndex", key);
    },
  },
};
</script>

<style lang="scss" scoped></style>
